<?php

namespace app\app\controller;

use app\BaseController;
use app\app\model\ProjectLiberaryModel;
use app\Request;


class ProjectLiberary extends BaseController
{
    public function index()
    {
        $data = $this->request->param();
        $page_size = input('pageSize', '20');
        $where = "1=1";
        if (!empty($data['fileName'])) {
            $where .= "  AND a.liberary_name like '%" . $data['fileName'] . "%'";
        }
        if (!empty($data['keyWord'])) {
            $where .= " AND a.key_word like '%" . $data['keyWord'] . "%'";
        }

        $list = ProjectLiberaryModel::alias('a')
            ->field('a.*,b.file_name,b.file_path,b.use_count')
            ->leftjoin('sys_file_info b', 'b.file_id = a.file_id')
            ->where($where)->paginate($page_size);
        $this->success('success', $list);
    }


    public function add(Request $request)
    {
        $data = $request->param();
        $data['oper_time'] = date('Y-m-d H:i:s', time());
        ProjectLiberaryModel::create($data);
        $this->success('success');
    }


}
